<template>
  <div>
    <div class="search">
      <van-search  placeholder="请输入搜索关键词" @click="$router.push('/searchpage')" />
    </div>
    <div class="cate-box">
      <catelist :cates="cates" class="cate-list"></catelist>

      <div class="cate-content">
        <cateconntent :cateObjeck="cateObjeck" @insert="insert"></cateconntent>
        
      </div>
<tabbar></tabbar>
    </div>
  </div>
</template>

<script>
//提示插件
import {Toast} from 'vant'
// 导航条
import tabbar from "@components/tabbar";
//引入数据请求方法
import { fetchCateBanner,fetchCateLocal } from "@api";
//引入子组件
import cateconntent from "./components/CateConntent";
import catelist from "./components/CateList";

//引入vuex方法
import {mapMutations} from 'vuex'
export default {
  data() {
    return {
      cates: [], //分类信息
      cateObjeck: [],//所选择分类下的商品信息
      OldName: "", //存储用户上一次选择的分类名称
    
      
    };
  },
  created() {


      console.log(this.cates);
      //请求所有分类信息
      fetchCateBanner().then((res) => {
        if (res.data.code === 200) {
        console.log(res.data.data);
       this.cates = res.data.data;
      }
    });
  },


  methods: {
    ...mapMutations(['changeNum','insert']),



    // 请求用户选择分类下的商品信息
    catedata: function (val) {
      //判断用户是否重复点击
      if (this.OldName === val) {
        return;
      } else {
        this.OldName = val;
        fetchCateLocal({
          query: val,
          page: 1,
          size: 9,
        }).then((res) => {
          if (res.data.code === 200) {
            this.cateObjeck = res.data.data.buynum;
          console.log(res.data.data);
          }
        });
      }
    },


  },
  components: {
    catelist: catelist,
    cateconntent: cateconntent,
    tabbar: tabbar,
  },
};
</script>

<style lang="scss" scoped>
.cate-box {
  width: 100%;
  display: flex;
  position: fixed;
  
  top: 56px;
  left: 0;
  padding-bottom: 180px;

  .cate-content {
    background: #f5f5f5;
    flex: 1;
    height: 100vh;
    overflow: auto;
    
    
  }
}
.cate-list {
  background: #f7f8fa;
  width: 80px;
  height: 100vh;
}
.search {
  width: 100%;
  height: 56px;
  background-color: black;
  padding-bottom: 10px;
  z-index: 10;
}
.van-search__content {
  background: #eee;
  width: 300px;
}
// .van-search{
//   width:70%;
// }
</style>